<?php

namespace app\model\not_del;

use app\model\ConsultTimeModel;
use think\Model;
use think\model\relation\BelongsTo;
use think\model\relation\HasMany;
use app\model\UserTagModel;

/**
 * 账号
 */
class UserModel extends Model
{
    protected $name = 'user';

    /**
     * 关联部门
     * @return BelongsTo
     */
    public function department(): BelongsTo
    {
        return $this->belongsTo(DepartmentModel::class,'department_id')->bind([
            'department_name'=>'name',
            'departmentAdmins',
        ]);
    }

    /**
     * 关联部门-部门名称
     * @return BelongsTo
     */
    public function departmentName(): BelongsTo
    {
        return $this->belongsTo(DepartmentModel::class,'department_id')->bind(['department_name'=>'name']);
    }

    /**
     * 关联部门-部门名称,学制模板
     * @return BelongsTo
     */
    public function departmentNameMode(): BelongsTo
    {
        return $this->belongsTo(DepartmentModel::class,'department_id')->bind(['department_name'=>'name','department_stage'=>'stage','department_mode'=>'mode','mode_name','level_rules']);
    }

    /**
     * 关联单位-单位名称
     * @return BelongsTo
     */
    public function unitName(): BelongsTo
    {
        return $this->belongsTo(UnitModel::class,'unit_id')->bind(['unit_name'=>'name']);
    }

    /**
     * 关联角色-角色名称
     * @return BelongsTo
     */
    public function roleName(): BelongsTo
    {
        return $this->belongsTo(RoleModel::class,'role_id')->bind(['role_name'=>'name']);
    }


    /**
     * 关联标签关系表
     * @return HasMany
     */
    public function userTag(): HasMany
    {
        return $this->hasMany(UserTagModel::class,'uid');
    }

    /**
     * 管理部门
     * @return HasMany
     */
    public function DepartmentAdmins(): HasMany
    {
        return $this->hasMany(DepartmentAdminModel::class,'uid');
    }

    /**
     * 咨询师排班
     * @return HasMany
     */
    public function ConsultTime(): HasMany
    {
        return $this->hasMany(ConsultTimeModel::class,'consult_id');
    }

}